<template>
	<gracePage :customHeader="false">
		<!-- 页面主体 -->
		<view slot="gBody" class="grace-body">
			<xw-empty :isShow="emptyShow" text="暂无数据" textColor="#777777"></xw-empty>
			
			<view class="" v-if="emptyShow==false">
				<view class="grace-card-view" v-for="(value, key) in listData" :key="key" >
					<view class="grace-card-body grace-border-b" @click="goEdit(value)">
						<view class="grace-card-desc">
							<view class="grace-card-title">
								<text class="grace-card-name">作物：{{ value.extMap.cropName }}</text>
								<text class="grace-card-name  text-blue">部位：{{ value.extMap.organName }}</text>
								<text class="grace-card-name  text-blue">生长期：{{ value.extMap.periodName }}</text>
							</view>
							<text class="grace-card-text">症状描述：{{ value.symptom }}</text>
							<text class="grace-card-text">发病时间：{{ value.diseasetime }}</text>
						</view>
					</view>
					<view class="grace-card-footer">
						<text class="das-icons  grace-card-footer-item grace-border-r text-green" @tap="goDetail(value)">&#xe600; 诊断详情</text>
						<text class="das-icons grace-card-footer-item grace-red" @tap="del(value,key)">&#xe601; 删除</text>
					</view>
				</view>
				<graceLoading :loadingType="loadingType"></graceLoading>
			</view>
		</view>
	</gracePage>
</template>
<script>
import gracePage from "../../plugin/graceUI/components/gracePage.vue";
import graceLoading from '../../plugin/graceUI/components/graceLoading.vue';
import xwEmpty from '@/components/xw-empty/xw-empty';
export default {
    data() {
    	return {
			emptyShow:false,//true显示，false隐藏
			listData: [],
			loadingType : 3,
			reload: false,//判断是否是下拉刷新
			pageNo:1,
			pageSize:10,
			isShow : false,//弹窗是否显示
    	}
    },
	onLoad() {
		this.getList();
		var this_=this;
		//添加监听刷新事件
		uni.$on('reloadBhzd',function(data){
			// console.log('监听到事件来自 shuaxin ，携带参数 msg 为：' + data.msg);
			this_.reload = true;
			this_.pageNo=1;
			this_.getList();
		})
	},
	onNavigationBarButtonTap(e) {
	   uni.navigateTo({
			url: './nswd_publish'
	   });
	},
	// 下拉刷新事件
	onPullDownRefresh: function (){
		this.reload = true;
		this.pageNo=1;
		this.getList();
	},
	onReachBottom : function(){
		//避免多次触发
		if (this.loadingType == 1 || this.loadingType == 2){return ;}
		this.reload = false;
		this.pageNo+=1;
		this.getList();
	},
	methods:{
		//查询数据
		getList: function (){
			//展示loading
			this.loadingType = 1;
			const user=uni.getStorageSync('user');
			uni.request({
				url: this.$config.apiUrl+"/diseaseController/myDiagnoseList/"+this.pageNo+"/"+this.pageSize,
				data: {
					appUserId:this.$store.getters.userid
				},
				success: data => {
					if (data.data.ok) {
						uni.stopPullDownRefresh();
						this.loadingType = 0;
						// let list = this.setTime(data.data);
						let list = data.data.data;
						if(list.length>0){
							// console.log(data.data)
							this.listData = this.reload ? list : this.listData.concat(list);
							
						}
						//判断是否继续加载数据
						if(list.length<this.pageSize){
							this.loadingType = 2;//已加载全部
						}
						
						if(this.listData.length>0){
							this.emptyShow=false;
						}else{
							this.emptyShow=true;
						}
					}
				},
				fail: (data, code) => {
					console.log('fail' + JSON.stringify(data));
				}
			});
		},
		goEdit: function(e) {
			uni.navigateTo({
				url: './bhzd_edit?id=' + e.id
			});
		},
		goDetail: function(e) {
			// this.$Router.push({name: 'bhzd', params:e.id})
			uni.navigateTo({
				url: './bhzd_edit?id=' + e.id
			});
		},
		
		//删除
		del: function(e,key) {
			var me_=this;
			uni.showModal({
			    title: '提示',
			    content: '确定删除么?',
			    success: function (res) {
			        if (res.confirm) {
			           uni.showLoading({
							title: '执行删除中...'
			           });
					   uni.request({
							url: me_.$config.apiUrl+"/diseaseController/delete/"+e.id,
							success: data => {
								if (data.data.ok) {
									uni.hideLoading();
									uni.showToast({
									    title: data.data.message,
									    duration: 2000
									});
									me_.listData.splice(key,1);
								}
							},
							fail: (data, code) => {
								console.log('fail' + JSON.stringify(data));
							}
					   });
			        } else if (res.cancel) {
			            // console.log('用户点击取消');
			        }
			    }
			});
		},
		
	},
	components:{
		gracePage,graceLoading,xwEmpty
	}
}
</script>
<style>
page{background-color:#F6F7F8;}
.grace-text-small{margin-top:10px;}
.content2{padding:30rpx; padding-right:80rpx; line-height:50rpx; font-size:26rpx;}
view{
	box-sizing: content-box;
}
</style>